<?php
namespace app\model;

use think\Model;
use think\facade\Db;
class StoreModel extends Model
{

    protected $pk = 'uniacid';
    // 设置当前模型对应的完整数据表名称
    protected $table = 'ims_uni_account';

    public static function createShop( $data ){

        $time = \time();
        $createSql = "INSERT INTO `ims_uni_account`(
            `groupid`, `name`, `description`, `default_acid`,
            `title_initial`,`logo`,`qrcode`, `createtime`,  `create_uid`) VALUES (
            0,
            '" . $data['name'] . "',
            '" . $data['name'] . "',
            0,
            '',
            '',
            '',
            " . $time . ",
            '" . $data['uid'] . "')";
         $ret = pdo_query( $createSql );
         if( !$ret ){

            return false;
         }
         $uniacid = pdo_insertid( 'ims_uni_account' );

         if( !$uniacid ){

            return false;
         }
         $joinSql = "INSERT INTO `ims_uni_account_users` set `uniacid`= ". $uniacid  
            . ",`uid`= ".$data['uid']  
            . ",`role`='owner',`rank`=0";
         $ret = pdo_query( $joinSql );

         return $uniacid?:0;
    }

    public static function searchByShopName( $shop_name ){

        $sql = 'select * from ims_uni_account where name="' . $shop_name . '"';

        return pdo_fetch( $sql );
    }

}